package com.pinyougou.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.ItemCat;
import com.pinyougou.service.ItemCatService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/itemCat")
public class ItemCatController {


    //注入ItemCatService
    @Reference(timeout = 10000)
    private ItemCatService itemCatService;

    @GetMapping("/findItemCatByParentId")
    public List<ItemCat> findItemCatByParentId(Long parentId){

        return itemCatService.findItemCatByParentId(parentId);

    }
   //保存添加的数据
    @PostMapping("/save")
    public boolean save(@RequestBody ItemCat itemCat){

        try {
            itemCatService.save(itemCat);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    //保存修改的数据
    @PostMapping("/update")
    public boolean update(@RequestBody ItemCat itemCat){
        try {
            itemCatService.update(itemCat);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;


    }


    //批量删除
    @GetMapping("/delete")
    public boolean delete(Long[]ids){

        try {
            itemCatService.deleteItemCat(ids);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;

    }




}
